package com.example.timedatedemo.slice;

import com.example.timedatedemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.TimePicker;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        // 获取时间选择器实例对象
        TimePicker picker = (TimePicker) findComponentById(ResourceTable.Id_time_picker);
        // 设置排列模式
        picker.setAmPmOrder(TimePicker.AmPmOrder.LEFT);
        // 设置是否24小时制
        picker.set24Hour(false);
        // 设置时
        picker.setHour(8);
        // 设置分
        picker.setMinute(45);
        // 设置秒
        picker.setSecond(40);
        // 设置显示文案
        picker.setAmString("上午");
        picker.setPmString("下午");
        // 设置字号
        picker.setNormalTextSize(60);
        picker.setSelectedTextSize(60);
        // 添加用户选择时间变更的监听
        picker.setTimeChangedListener(new TimePicker.TimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker timePicker, int hour, int minute, int second) {
                // 获取用户选择的时间
            }
        });

        // 设置时分秒对应的选项栏是否可修改
        picker.enableHour(true);
        picker.enableMinute(true);
        picker.enableSecond(true);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
